package com.api.demo.test.business;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.api.demo.dto.business.company.*;
import com.api.demo.util.ApiSignUtil;
import com.api.demo.util.CommonUtil;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @description: 商户相关
 * @author: yanming
 * @createDate: 2022/12/26 14:27
 */
public class Company {


    /**
     * 添加商户请求接口
     */
    public static String addCompanyPath = "%s/api/company/add";

    /**
     * 查询商户审核状态v2
     */
    public static String companyAuditStatusPath = "%s/api/company/audit-status-v2";

    /**
     * 查询可合作的服务商列表V2
     */
    public static String taxListPath = "%s/api/company/tax-list-v2";

    /**
     * 查询可合作的服务商列表V2
     */
    public static String applyCooperationPath = "%s/api/company/apply-cooperation";

    /**
     * 查询与服务商合作状态V2
     */
    public static String applyCooperationStatusPath = "%s/api/company/apply-cooperation-status-v2";

    /**
     * 查询账户信息V2
     */
    public static String accountInfoPath = "%s/api/company/account-info-v2";

    /**
     * 线下充值
     */
    public static String offlineRechargePath = "%s/api/company/offline-recharge";

    /**
     * 查询充值记录V2
     */
    public static String rechargeRecordPath = "%s/api/company/recharge-record-v2";


    /**
     * 平安入金记录查询V2
     */
    public static String paPayGoldenInfoPath = "%s/api/company/pa-pay-golden-info-v2";


    public static void main(String[] args) {

        /**
         * 添加商户
         */
//        addCompany();

        /**
         * 查询商户审核状态v2
         */
//        getCompanyAuditStatus();

        /**
         * 查询可合作的服务商列表V2
         */
//        taxList();

        /**
         * 申请与服务商合作
         */
//        applyCooperation();

        /**
         * 查询与服务商合作状态v2
         */
//        applyCooperationStatus();


        /**
         * 查询账户信息
         */
//        accountInfo();


        /**
         * 线下充值
         */
//        offlineRecharge();

        /**
         * 查询充值记录
         */
//        rechargeRecord();

        /**
         * 查询平安入金记录
         */
//        paPayGoldenInfo();

    }


    /**
     * 添加商户
     */
    public static void addCompany() {

        CompanyApiDTO companyApiDTO = new CompanyApiDTO();
        //接口必要参数
        companyApiDTO.setAgentId(CommonUtil.AGENT_ID);
        companyApiDTO.setTimestamp(System.currentTimeMillis());

        //基本信息  （测试需要换商户名称和信用代码，其余可以不用换）
        companyApiDTO.setCompanyName("业务测试api-商户01");
        companyApiDTO.setCreditCode(CommonUtil.creditCode);

        companyApiDTO.setCompanyMan("法人名称");
        companyApiDTO.setMobile("15099990637");
        companyApiDTO.setIdCardCode("430422199604279999");
        companyApiDTO.setSetUpDate("2022-01-01");
        companyApiDTO.setBusinessScope("经营范围");
        companyApiDTO.setCompanyProvince("湖南省衡阳市");
        companyApiDTO.setIndustry("所属行业");
        companyApiDTO.setBankCode("12312312312");
        companyApiDTO.setBankName("中国银行");
        companyApiDTO.setBusinessLicense("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1/20221226/c8854dd04f164b1daf9218925a80f803.png");
        companyApiDTO.setContract("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1504655422236135425/20220402/8149eb246b404c57a883c7d29d404069.pdf");
        companyApiDTO.setPrivacyAgreement("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1504655422236135425/20220402/8149eb246b404c57a883c7d29d404069.pdf");

        //开票信息
        companyApiDTO.setInvoiceCompanyName("测试商户001");
        companyApiDTO.setInvoiceAddress("湖南省衡阳市*********");
        companyApiDTO.setInvoiceMobile("15099990637");
        companyApiDTO.setInvoiceTaxCode("DA1243129FS1412312");


        //联系人
        companyApiDTO.setLinkMan("联系人");
        companyApiDTO.setLinkMobile("15099990637");
        companyApiDTO.setLinkIdCardCode("430422199604279999");
        companyApiDTO.setLinkEmail("3906448@qq.com");

        //快递信息
        companyApiDTO.setDeliveryArea("广州市白云区");
        companyApiDTO.setAddressDesc("太和镇谢家庄********");
        companyApiDTO.setAddressee("收件人");
        companyApiDTO.setAddresseeMobile("15099990637");

        //业务信息
        companyApiDTO.setInvoiceCategory("*现代服务*人力资源服务,*现代服务*企业形象策划,*文化服务*文化服务");
        companyApiDTO.setSettleAccounts("结算业务场景-结算兼职人员的佣金");

        //非必填参数
//        companyApiDTO.setCompanySize("6");
//        companyApiDTO.setPrivacyAgreement("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1/20221226/c8854dd04f164b1daf9218925a80f803.png");
//        companyApiDTO.setOpenLicense("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1/20221226/c8854dd04f164b1daf9218925a80f803.png");
//        companyApiDTO.setCompanyLogo("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1/20221226/c8854dd04f164b1daf9218925a80f803.png");
//        companyApiDTO.setIdCardBack("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1/20221226/c8854dd04f164b1daf9218925a80f803.png");
//        companyApiDTO.setIdCardFront("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1/20221226/c8854dd04f164b1daf9218925a80f803.png");
//        companyApiDTO.setDoorplatePicture("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1/20221226/c8854dd04f164b1daf9218925a80f803.png");
//        companyApiDTO.setFrontDeskPicture("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1/20221226/c8854dd04f164b1daf9218925a80f803.png");
//        companyApiDTO.setOfficePicture("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1/20221226/c8854dd04f164b1daf9218925a80f803.png");
//        companyApiDTO.setTaxDeclare("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1/20221226/c8854dd04f164b1daf9218925a80f803.png");
//        companyApiDTO.setMoreDesc("更多说明");


        //参与加密的参数    固定的几个字段缺一不可
        Map<String, Object> signMap = new HashMap<>(5);
        signMap.put("agentId", companyApiDTO.getAgentId());
        signMap.put("timestamp", companyApiDTO.getTimestamp());
        signMap.put("key", CommonUtil.KEY);
        signMap.put("creditCode", companyApiDTO.getCreditCode());
        signMap.put("companyName", companyApiDTO.getCompanyName());
        String sign = ApiSignUtil.getSign(JSON.parseObject(JSON.toJSONString(signMap)));
        System.out.println(sign);
        companyApiDTO.setSign(sign);

        //请求地址
        String url = String.format(addCompanyPath, CommonUtil.REQUEST_URL);
        System.out.println("请求地址： " + url);
        String post = HttpUtil.post(url, JSON.toJSONString(companyApiDTO));
        System.out.println(post);
    }


    /**
     * 查询审核状态v2
     */
    public static void getCompanyAuditStatus() {
        CompanyAuditStatusDTO companyAuditStatusDTO = new CompanyAuditStatusDTO();
        companyAuditStatusDTO.setAgentId(CommonUtil.AGENT_ID);
        companyAuditStatusDTO.setTimestamp(System.currentTimeMillis());
        companyAuditStatusDTO.setCreditCode(CommonUtil.creditCode);

        //参与加密的参数    固定的几个字段缺一不可
        Map<String, Object> signMap = new HashMap<>(4);
        signMap.put("agentId", companyAuditStatusDTO.getAgentId());
        signMap.put("timestamp", companyAuditStatusDTO.getTimestamp());
        signMap.put("key", CommonUtil.KEY);
        signMap.put("creditCode", companyAuditStatusDTO.getCreditCode());
        String sign = ApiSignUtil.getSign(JSON.parseObject(JSON.toJSONString(signMap)));
        System.out.println(sign);
        companyAuditStatusDTO.setSign(sign);

        String url = String.format(companyAuditStatusPath, CommonUtil.REQUEST_URL);
        System.out.println("请求地址： " + url);

        String post = HttpUtil.post(url, JSON.toJSONString(companyAuditStatusDTO));
        System.out.println(post);

    }

    /**
     * 查询可合作的服务商列表V2
     */
    public static void taxList() {
        TaxListDTO taxListDTO = new TaxListDTO();
        taxListDTO.setAgentId(CommonUtil.AGENT_ID);
        taxListDTO.setTimestamp(System.currentTimeMillis());
        taxListDTO.setPageNo(1);
        taxListDTO.setPageSize(10);

        //非必填参数
//        taxListDTO.setTaxName("");


        //参与加密的参数    固定的几个字段缺一不可
        Map<String, Object> signMap = new HashMap<>(3);
        signMap.put("agentId", taxListDTO.getAgentId());
        signMap.put("timestamp", taxListDTO.getTimestamp());
        signMap.put("key", CommonUtil.KEY);
        String sign = ApiSignUtil.getSign(JSON.parseObject(JSON.toJSONString(signMap)));
        System.out.println(sign);
        taxListDTO.setSign(sign);

        //请求地址
        String url = String.format(taxListPath, CommonUtil.REQUEST_URL);
        System.out.println("请求地址： " + url);
        String post = HttpUtil.post(url, JSON.toJSONString(taxListDTO));
        System.out.println(post);

    }

    /**
     * 申请与服务商合作
     */
    public static void applyCooperation() {
        ApplyCooperationDTO applyCooperationDTO = new ApplyCooperationDTO();
        applyCooperationDTO.setCreditCode(CommonUtil.creditCode);
        applyCooperationDTO.setAgentId(CommonUtil.AGENT_ID);
        applyCooperationDTO.setTimestamp(System.currentTimeMillis());
        applyCooperationDTO.setTaxId(CommonUtil.TAX_ID);
        applyCooperationDTO.setMaxTaxPrice(new BigDecimal("10"));
        applyCooperationDTO.setMinTaxPrice(new BigDecimal("10"));

        //参与加密的参数    固定的几个字段缺一不可
        Map<String, Object> signMap = new HashMap<>(5);
        signMap.put("agentId", applyCooperationDTO.getAgentId());
        signMap.put("timestamp", applyCooperationDTO.getTimestamp());
        signMap.put("key", CommonUtil.KEY);
        signMap.put("creditCode", applyCooperationDTO.getCreditCode());
        signMap.put("taxId", applyCooperationDTO.getTaxId());

        String sign = ApiSignUtil.getSign(JSON.parseObject(JSON.toJSONString(signMap)));
        System.out.println(sign);
        applyCooperationDTO.setSign(sign);

        //请求地址
        String url = String.format(applyCooperationPath, CommonUtil.REQUEST_URL);
        System.out.println("请求地址： " + url);
        String post = HttpUtil.post(url, JSON.toJSONString(applyCooperationDTO));
        System.out.println(post);

    }

    /**
     * 查询与服务商合作状态v2
     */
    public static void applyCooperationStatus() {
        ApplyCooperationStatusDTO applyCooperationStatusDTO = new ApplyCooperationStatusDTO();
        applyCooperationStatusDTO.setCreditCode(CommonUtil.creditCode);
        applyCooperationStatusDTO.setAgentId(CommonUtil.AGENT_ID);
        applyCooperationStatusDTO.setTimestamp(System.currentTimeMillis());
        applyCooperationStatusDTO.setTaxId(CommonUtil.TAX_ID);


        //参与加密的参数    固定的几个字段缺一不可
        Map<String, Object> signMap = new HashMap<>(4);
        signMap.put("agentId", applyCooperationStatusDTO.getAgentId());
        signMap.put("timestamp", applyCooperationStatusDTO.getTimestamp());
        signMap.put("key", CommonUtil.KEY);
        signMap.put("creditCode", applyCooperationStatusDTO.getCreditCode());
        signMap.put("taxId", applyCooperationStatusDTO.getTaxId());

        String sign = ApiSignUtil.getSign(JSON.parseObject(JSON.toJSONString(signMap)));
        System.out.println(sign);
        applyCooperationStatusDTO.setSign(sign);

        //请求地址
        String url = String.format(applyCooperationStatusPath, CommonUtil.REQUEST_URL);
        System.out.println("请求地址： " + url);
        String post = HttpUtil.post(url, JSON.toJSONString(applyCooperationStatusDTO));
        System.out.println(post);

    }

    /**
     * 查询账户信息V2
     */
    public static void accountInfo() {
        AccountInfoDTO accountInfoDTO = new AccountInfoDTO();
        accountInfoDTO.setCreditCode(CommonUtil.creditCode);
        accountInfoDTO.setAgentId(CommonUtil.AGENT_ID);
        accountInfoDTO.setTimestamp(System.currentTimeMillis());

        //非必填参数
        accountInfoDTO.setTaxId(CommonUtil.TAX_ID);


        //参与加密的参数    固定的几个字段缺一不可
        Map<String, Object> signMap = new HashMap<>(5);
        signMap.put("agentId", accountInfoDTO.getAgentId());
        signMap.put("timestamp", accountInfoDTO.getTimestamp());
        signMap.put("key", CommonUtil.KEY);
        signMap.put("creditCode", accountInfoDTO.getCreditCode());
        signMap.put("taxId", accountInfoDTO.getTaxId());

        String sign = ApiSignUtil.getSign(JSON.parseObject(JSON.toJSONString(signMap)));
        System.out.println(sign);
        accountInfoDTO.setSign(sign);

        //请求地址
        String url = String.format(accountInfoPath, CommonUtil.REQUEST_URL);
        System.out.println("请求地址： " + url);
        String post = HttpUtil.post(url, JSON.toJSONString(accountInfoDTO));
        System.out.println(post);

    }


    /**
     * 线下充值
     */
    public static void offlineRecharge() {
        OfflineRechargeDTO offlineRechargeDTO = new OfflineRechargeDTO();
        offlineRechargeDTO.setCreditCode(CommonUtil.creditCode);
        offlineRechargeDTO.setAgentId(CommonUtil.AGENT_ID);
        offlineRechargeDTO.setTimestamp(System.currentTimeMillis());
        offlineRechargeDTO.setTaxId(CommonUtil.TAX_ID);
        offlineRechargeDTO.setPayReceiptUrl("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1/20221226/c8854dd04f164b1daf9218925a80f803.png");
        offlineRechargeDTO.setMoney(new BigDecimal("100"));

        //参与加密的参数    固定的几个字段缺一不可
        Map<String, Object> signMap = new HashMap<>(5);
        signMap.put("agentId", offlineRechargeDTO.getAgentId());
        signMap.put("timestamp", offlineRechargeDTO.getTimestamp());
        signMap.put("key", CommonUtil.KEY);
        signMap.put("creditCode", offlineRechargeDTO.getCreditCode());
        signMap.put("taxId", offlineRechargeDTO.getTaxId());


        String sign = ApiSignUtil.getSign(JSON.parseObject(JSON.toJSONString(signMap)));
        System.out.println(sign);
        offlineRechargeDTO.setSign(sign);

        //请求地址
        String url = String.format(offlineRechargePath, CommonUtil.REQUEST_URL);
        System.out.println("请求地址： " + url);
        String post = HttpUtil.post(url, JSON.toJSONString(offlineRechargeDTO));
        System.out.println(post);

    }


    /**
     * 查询充值记录V2
     */
    public static void rechargeRecord() {

        RechargeRecordDTO rechargeRecordDTO = new RechargeRecordDTO();
        rechargeRecordDTO.setAgentId(CommonUtil.AGENT_ID);
        rechargeRecordDTO.setTimestamp(System.currentTimeMillis());
        rechargeRecordDTO.setCreditCode(CommonUtil.creditCode);

        //非必填参数
        rechargeRecordDTO.setTaxId(CommonUtil.TAX_ID);
//        rechargeRecordDTO.setStartDate("2023-11-11");
//        rechargeRecordDTO.setEndDate("2023-11-11");
//        rechargeRecordDTO.setTpId(1762411029251231746L);


        //参与加密的参数    固定的几个字段缺一不可
        Map<String, Object> signMap = new HashMap<>(5);
        signMap.put("agentId", rechargeRecordDTO.getAgentId());
        signMap.put("timestamp", rechargeRecordDTO.getTimestamp());
        signMap.put("key", CommonUtil.KEY);
        signMap.put("creditCode", rechargeRecordDTO.getCreditCode());
        signMap.put("taxId", rechargeRecordDTO.getTaxId());


        String sign = ApiSignUtil.getSign(JSON.parseObject(JSON.toJSONString(signMap)));
        System.out.println(sign);
        rechargeRecordDTO.setSign(sign);

        //请求地址
        String url = String.format(rechargeRecordPath, CommonUtil.REQUEST_URL);
        System.out.println("请求地址： " + url);
        String post = HttpUtil.post(url, JSON.toJSONString(rechargeRecordDTO));
        System.out.println(post);

    }

    /**
     * 查询平安入金记录
     */
    public static void paPayGoldenInfo(){
        PaPayGoldenInfoDTO paPayGoldenInfoDTO = new PaPayGoldenInfoDTO();
        paPayGoldenInfoDTO.setEndDate("20240110000000");
        paPayGoldenInfoDTO.setStartDate("20240310000000");
        paPayGoldenInfoDTO.setPageSize(1000);
        paPayGoldenInfoDTO.setPageNo(1);
        paPayGoldenInfoDTO.setTaxId(CommonUtil.TAX_ID);
        paPayGoldenInfoDTO.setCreditCode(CommonUtil.creditCode);
        paPayGoldenInfoDTO.setAgentId(CommonUtil.AGENT_ID);
        paPayGoldenInfoDTO.setTimestamp(System.currentTimeMillis());


        //参与加密的参数    固定的几个字段缺一不可
////        Map<String, Object> signMap = new HashMap<>(5);
////        signMap.put("agentId", rechargeRecordDTO.getAgentId());
////        signMap.put("timestamp", rechargeRecordDTO.getTimestamp());
////        signMap.put("key", CommonUtil.KEY);
////        signMap.put("creditCode", rechargeRecordDTO.getCreditCode());
////        signMap.put("taxId", rechargeRecordDTO.getTaxId());
//
//
//        String sign = ApiSignUtil.getSign(JSON.parseObject(JSON.toJSONString(signMap)));
//        System.out.println(sign);
        paPayGoldenInfoDTO.setSign("123");

        //请求地址
        String url = String.format(paPayGoldenInfoPath, CommonUtil.REQUEST_URL);
        System.out.println("请求地址： " + url);
        String post = HttpUtil.post(url, JSON.toJSONString(paPayGoldenInfoDTO));
        System.out.println(post);


    }





}